<?php $this->load->view('provider/template/_begin') ?>
<script type="text/javascript">
  var country_id = 0,state_id = 0;
  jQuery(document).ready(function(){
    jQuery('#form_signup').validationEngine();
    $('#country_id').bind({
      change: function (){detect_country($(this).val());},
      blur: function (){detect_country($(this).val());}
    });
    $('#state_id').bind({
      change: function (){detect_state($(this).val());},
      blur: function (){detect_state($(this).val());}
    });
    detect_country($('#country_id').val());
  });
  function detect_country(id){
    if(country_id != id){
      country_id = id;
      $('#state_id').html('');
      $('#state_id').html('<option value=""><?php echo $this->lang->line('label.state.select') ?></option>');
      if(id){
        $.post('<?php echo site_url('admin/ajax/list_json_state') ?>', {id : id}, function(data){
          if(data){                
            $.each(data, function(key, value){
              $('#state_id').append('<option '+
                (value['id'] == '<?php echo isset($obj['state_id']) ? $obj['state_id'] : 0 ?>' ? 'selected="selected"' :'' )
                +' value="'+value['id']+'">'+ value['name'] +'</option>');
            })
          }
        }, 'json');
      }
    }
  }
  function detect_state(id){
    if(state_id != id){
      state_id = id;
      $('#city_id').html('');
      $('#city_id').html('<option value=""><?php echo $this->lang->line('label.city.select') ?></option>');
      if(id){
        $.post('<?php echo site_url('admin/ajax/list_json_city') ?>', {id : id}, function(data){
          if(data){                
            $.each(data, function(key, value){
              $('#city_id').append('<option '+
                (value['id'] == '<?php echo isset($obj['city_id']) ? $obj['city_id'] : 0 ?>' ? 'selected="selected"' :'' )
                +' value="'+value['id']+'">'+ value['name'] +'</option>');
            })
          }
        }, 'json');
      }
    }
  }
</script>
<div class="form1">  
  <form action="<?php echo site_url('provider/profile/update') ?>" method="post" enctype="multipart/form-data" id="form_signup">
    <table class="table1">
      <tr>
        <td class="text4">Username<span>*</span>:</td>
        <td><label><?php echo empty($obj["username"]) ? "" : $obj["username"] ?></label></td>
        <td class="text4">First name:</td>
        <td><input id="first_name" type="text" name="first_name" class="input1"
                   value="<?php echo empty($obj["first_name"]) ? "" : $obj["first_name"] ?>" /></td>

      </tr>
      <tr>
        <td class="text4">Email<span>*</span>:</td>
        <td>
          <input id="email" type="text" name="email" 
                 class="input1 validate[required,custom[email]]"
                 value="<?php echo empty($obj["email"]) ? "" : $obj["email"] ?>"/>          
        </td>
        <td class="text4">Last name:</td>
        <td><input id="last_name" type="text" name="last_name" class="input1"
                   value="<?php echo empty($obj["last_name"]) ? "" : $obj["last_name"] ?>" /></td>

      </tr>
      <tr>
        <td class="text4">Password<span>*</span>:</td>
        <td>
          <input id="password" type="password" name="password" value="" 
                 class="input1 validate[minSize[6]]"/>
        </td>
        <td class="text4">Homepage:</td>
        <td><input id="edtLogin" type="text" name="home_page" class="input1"
                   value="<?php echo empty($obj["home_page"]) ? "" : $obj["home_page"] ?>"/></td>
      </tr>
      <tr>
        <td class="text4">Confirm password<span>*</span>:</td>
        <td>
          <input id="edtLogin" type="password" name="confirm_pass" value="" 
                 class="input1 validate[equals[password]]"/>          
        </td>
        <td class="text4">Phone<span>*</span>:</td>
        <td><input id="phone" type="text" name="phone" class="input1 validate[required]"
                   value="<?php echo empty($obj["phone"]) ? "" : $obj["phone"] ?>"/></td>
      </tr>
      <tr>
        <td class="text4">Address<span>*</span>:</td>
        <td><input id="address" type="text" name="address" class="input1 validate[required]"
                   value="<?php echo empty($obj["address"]) ? "" : $obj["address"] ?>"/></td>
        <td class="text4">Company name:</td>
        <td><input id="edtLogin" type="text" name="company_name" class="input1"
                   value="<?php echo empty($obj["company_name"]) ? "" : $obj["company_name"] ?>"/></td>
      </tr>
      <tr>
        <td class="text4">Select country<span>*</span>:</td>
        <td>
          <select class="select1 validate[required]" name="country_id" id="country_id">
            <option value=""><?php echo $this->lang->line('label.option.select') ?></option>
            <?php
            $ref_objs = $this->country_model->get_all();
            foreach ($ref_objs as $ref) {
              ?>
              <option value="<?php echo $ref["id"] ?>"
                      <?php echo empty($obj["country_id"]) || $obj["country_id"] != $ref["id"] ? "" : 'selected="selected"' ?>>
                        <?php echo $this->country_model->to_string($ref) ?>
              </option>
            <?php } ?>
          </select>
        </td>
        <td class="text4">Fax:</td>
        <td><input id="edtLogin" type="text" name="fax" class="input1"
                   value="<?php echo empty($obj["fax"]) ? "" : $obj["fax"] ?>"/></td>
      </tr>
      <tr>
        <td class="text4">Select state<span>*</span>:</td>
        <td>
          <select class="select1 validate[required]" name="state_id" id="state_id">
            <option value=""><?php echo $this->lang->line('label.option.select') ?></option>
          </select>
        </td>
        <td class="text4">Avatar:</td>
        <td ><input class="" type="file" size="50" name="avatar"/></td>
      </tr>
      <tr>
        <td class="text4">Select city<span>*</span>:</td>
        <td>
          <select class="select1 validate[required]" name="city_id" id="city_id">
            <option value=""><?php echo $this->lang->line('label.option.select') ?></option>
          </select>
        </td>
      </tr>
      <tr>
        <td colspan="4">
          <div class="button">
            <div class="button_left"></div>
            <div class="button_bg"><a href="#" onclick="$('form').submit();return false;">Save</a></div>
            <div class="button_right"></div>
          </div>
        </td>
      </tr>
    </table>
  </form>
</div> 
<?php $this->load->view('provider/template/_end') ?>